var viewFactory = (function() {
	

	var assetView = new AssetEntryView({ 
			el :$('<div class="view-helper"></div>')
				.appendTo(document.body)
	});
	var rootView = new RUBase({ 
			el :$('<div class="view-helper"></div>')
				.appendTo(document.body),
			module: "Root"
	});
	var uricView = new RUBase({ 
			el :$('<div class="view-helper"></div>')
				.appendTo(document.body),
			module: "URIC"
	});
	var bulkEntryView = new BulkEntryView({
			el :$('<div class="view-helper"></div>')
				.appendTo(document.body)
	});	
	var EmptyView = Backbone.View.extend({
		tagName: "div",
		initialize : function() {
			this.body = $("<div>").appendTo(this.$el);
		}
	});
	var EmptyBlockView1 = new EmptyView({
		el :$('<div class="view-helper"></div>')
				.appendTo(document.body)		
	});
	var EmptyBlockView2 = new EmptyView({
		el :$('<div class="view-helper"></div>')
				.appendTo(document.body)		
	});
	var EmptyBlockView3 = new EmptyView({
		el :$('<div class="view-helper"></div>')
				.appendTo(document.body)		
	});
	var EmptyView0 = new EmptyView({
		el :$('<div class="view-helper"></div>')
				.appendTo(document.body)		
	});
	var EmptyBlockView4 = new EmptyView({
		el :$('<div class="view-helper"></div>')
				.appendTo(document.body)		
	});

	return {
		AssetLine : function() {
			assetView.line = true;
			return assetView;
		},
		AssetBlock : function() {
			assetView.line = false;
			return assetView;
		},
		AssetDetailBlock: function(){
			return EmptyBlockView1;
		},
		BulkEntryView : function(){
			return bulkEntryView;
		},		
		BulkBlockView : function(){			
			return EmptyBlockView4;
		},		
		RootEntryBlock: function(){
			rootView.line = false;
			return rootView;
		}
		,
		RootEntryLine: function(){
			rootView.line = true;
			return rootView;
		},
		RootDetailBlock: function(){
			return EmptyBlockView2;
		},
		
		URICEntryBlock: function(){
			uricView.line = false;
			return uricView;
		}
		,
		URICEntryLine: function(){
			uricView.line = true;
			return uricView;
		},
		URICDetailBlock: function(){
			return EmptyBlockView3;
		},
		HiddenView: function(){
			return EmptyView0;
		}
	};

})();

var bulk_page_readOnly = true, bulk_con = new ItemModel({
	schema: bulkload
});

var bulk_asset = new Backbone.Asset({
	model : bulk_con,
	readOnly : bulk_page_readOnly
}).render();



var func = { // this is panel-container.
	asset: function(){
		// this.block.model.set({sub:"Futures Option Quote"});
	},
	root: function(){
		// this.block;
	},
	bulkload : function() {
		if(ViewData.Login.usr){
			if(ViewData.Login.Bulk == 1){
				if (prio) prio.css("display", "block");
				if (prioSearch) prioSearch.css("display", "block");
				
				$(".panel-container[name|='Bulk'] th[data-field|='priority']").css("display", "block");
				$(".panel-container[name|='Bulk'] td[colname|='priority']").css("display", "block");
			}
		}else{
			$(".panel-container[name|='Bulk'] th[data-field|='priority']").css("display", "none");
			$(".panel-container[name|='Bulk'] td[colname|='priority']").css("display", "none");
		}
	},
	constructPage: function(page_readOnly, page_cne, wrapperView, data, callback){	

		var module = page_cne.module, g = PT.groupArray[module];
		if(g){
			if (!g.flag) {

				var con = new ItemModel({
					schema : page_cne
				});

				var asset = new Backbone.Asset({
					model : con,
					readOnly : page_readOnly
				}).render();

				wrapperView.body.children().hide();
				wrapperView.body.append(asset.el);
				wrapperView.inner = asset;	
				
				g.flag = true;
				g.obj = asset;
				g.wraper = wrapperView.body;
				// set values
				if(data) asset.setValue(data);
				if(callback){
					callback(asset);
				}				
				return asset;
			}
		}else{
			alert("Configuration Error: Page module is not set.");
			return false;
		}		
	}
};
var view_model = {
	Asset:{
		entry : ["", "AssetBlock"],
		actions : {
			"click .search-box .btn.go" : ["zoom", ["toggle", ["AssetLine", "AssetDetailBlock"]]]
			
		}
	},
	Bulk:{
		entry : ["", "BulkEntryView"],
		actions : {
			"click #btnbulkload" : [["zoom", func.bulkload],["toggle", ["", "BulkBlockView"]]]
		}
	},


	Root:{
		entry : ["", "RootEntryBlock"],
		actions : {
			"dblclick .result-table tbody tr" : ["zoom", ["toggle", ["", "RootDetailBlock"]]]
			
		}		
	},
	URIC:{
		entry : ["", "URICEntryBlock"],
		actions : {
			"dblclick .result-table tbody tr" : ["zoom", ["toggle", ["URICEntryLine", "URICDetailBlock"]]]
			
		}		
	}	
}; 

